//
//  WBHomeViewController.swift
//  小荣荣新浪微博
//
//  Created by zzr on 2018/4/19.
//  Copyright © 2018年 zzr. All rights reserved.
//

import UIKit

let tableCellID = "tableCellID"

class WBHomeViewController: WBBaseViewController {

    private lazy var statusList = [String]()
    
    //MARK: - 系统回调
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    //MARK: - 设置界面
    override func setupUI() {
        super.setupUI()
        
        //设置导航栏按钮
        //无法高亮
        //navigationItem.leftBarButtonItem = UIBarButtonItem(title: "好友", style: .plain, target: self, action: #selector(showFriends))
        let uui = UIBarButtonItem(title: "好友", target: self, action: #selector(showFriends))
        navItem.leftBarButtonItem = uui
        
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: tableCellID)
    }

    
    //MARK: - 监听方法
    @objc fileprivate func showFriends() {
        print(#function)
        let vc = WBDemoViewController()
        //vc.hidesBottomBarWhenPushed = true
        navigationController?.pushViewController(vc, animated: true)
    }
    
    //MARK: - 加载数据
    override func loadData() {
        
        //开始加载数据
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1) {
            for i in 0..<15 {
                if self.isPullup {
                    self.statusList.append("上拉\(i)")
                } else {
                    self.statusList.insert(i.description, at: 0)
                }
                
            }
            print("刷新表格")
            self.refreshControl?.endRefreshing()
            //恢复上拉刷新
            self.isPullup = false
            //刷新表格
            self.tableView?.reloadData()
        }
        
        
    }
}

//MARK: - 表格数据源方法
extension WBHomeViewController {
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusList.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: tableCellID, for: indexPath)
        cell.textLabel?.text = statusList[indexPath.row]
        return cell
    }
    
}






